package tt.dz.service.impl;

import java.io.Serializable;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import tt.dz.common.Constants;
import tt.dz.dao.pro.UserRechargeBillDao;
import tt.dz.entity.UserRechargeBill;
import tt.dz.service.UserRechargeService;

/**
 * 用户充值业务实现
 * @author Administrator
 *
 */
@Service
public class UserRechargeServiceImpl implements UserRechargeService{

	/**用户充值操作Dao*/
	@Resource
	UserRechargeBillDao<UserRechargeBill> userRechargeBillDao;

	@Override
	public String userRecharge(UserRechargeBill userRechargeBill) {
		
		userRechargeBill.setRechange_result(0);
		userRechargeBill.setUpdate_time(new Date());
		Serializable serializable = userRechargeBillDao.save(userRechargeBill);
		if(serializable!=null){
			return Constants.JsonResponseCode.SUCCESS;
		}
		return Constants.JsonResponseCode.FAIL;
	}

	@Override
	public String finishRechargeBill(String alipayTradeNum,Integer userId) {
		
		UserRechargeBill userRechargeBill = userRechargeBillDao.findUserRechargeByRechargeIdAndUserId(alipayTradeNum,userId);
		if(userRechargeBill==null){
			return Constants.JsonResponseCode.ORDER_NOT_EXISTS;
		}
		userRechargeBill.setRechange_result(1);
		userRechargeBill.setUpdate_time(new Date());
		userRechargeBillDao.update(userRechargeBill);
		return Constants.JsonResponseCode.SUCCESS;
	}
}
